package top.zsc.cloud.common.dao;

import top.zsc.cloud.common.vo.QueryParams;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import tk.mybatis.mapper.annotation.RegisterMapper;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;

/***
 * @title:<h3> mybatis通用mapper配置扩展 <h3>
 * @author: Enzo
 * @date: 2018-12-19 23:23
 * @params
 * @return
 **/
@RegisterMapper
public interface MapperCustom<T> extends Mapper<T> ,MySqlMapper<T> {

    /***
     * @title:<h3> 新增业务扩展，默认添加乐观锁、删除标记、创建时间 <h3>
     * @author: Enzo
     * @date: 2018-12-19 23:23
     * @params [record]
     * @return int
     **/
    @InsertProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    int insertService(T record);

    /***
     * @title:<h3> 修改业务扩展，添加修改人、修改时间、乐观锁 <h3>
     * @author: Enzo
     * @date: 2019-1-15 1:01
     * @params [record]
     * @return int
     **/
    @UpdateProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    int updateService(T record);

    /***
     * @title:<h3> 逻辑删除 <h3>
     * @author: Enzo
     * @date: 2019-1-14 22:52
     * @params [record]
     * @return int
     **/
    @UpdateProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    int remove(T record);

    /***
     * @title:<h3> 根据主键逻辑删除 <h3>
     * @author: Enzo
     * @date: 2019-1-14 22:52
     * @params [record]
     * @return int
     **/
    @UpdateProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    /***
     * @title:<h3> 根据id逻辑删除 <h3>
     * @author: Enzo
     * @date: 2019-1-15 1:02
     * @params [record]
     * @return int
     **/
    int removeByPk(T record);

    @UpdateProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    /***
     * @title:<h3> 批量删除 <h3>
     * @author: Enzo
     * @date: 2019-1-14 23:43
     * @params [pks]
     * @return int
     **/
    int removeInPk(String pks);

    /***
     * @title:<h3> 根据字段批量删除数据 <h3>
     * @author: Enzo
     * @date: 2019-1-15 1:01
     * @params [column, fieldValue]
     * @return int
     **/
    @UpdateProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    int removeInColumnFieldValue(@Param("column") String column, @Param("fieldValue") String fieldValue);

    /***
     * @title:<h3> 根据条件逻辑删除 <h3>
     * @author: Enzo
     * @date: 2019-1-15 1:27
     * @params [where]
     * @return int
     **/
    @UpdateProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    int removeByWhere(@Param("where") String where);

    /***
     * @title:<h3> 查询全部未删除记录 <h3>
     * @author: Enzo
     * @date: 2019-1-14 23:03
     * @params []
     * @return java.util.List<T>
     **/
    @SelectProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    List<T> findAll();

    /***
     * @title:<h3> 根据条件查询 <h3>
     * @author: Enzo
     * @date: 2019-1-15 1:04
     * @params [whrere]
     * @return java.util.List<T>
     **/
    @SelectProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    List<T> findByWhere(@Param("where") String where);

    @SelectProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    List<T>findByQueryParams(QueryParams queryParams);

/**
* @title:<h3> 根据条件查询记录数</h3>
* @author: Enzo
* @date: 2019-1-22 15:51
* @params [where]
* @return java.util.List<T>
**/
    @SelectProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
   int countByWhere(@Param("where") String where);
    /**
    * <h3>条件更新，忽略主键</h3>
    * @params [var1, var2]
    * @author Enzo
    * @date 2019-3-25  15:42
    * @return int
    */
    @UpdateProvider(
            type = MapperCustomProvider.class,
            method = "dynamicSQL"
    )
    int updateByExampleService(@Param("record") T var1, @Param("example") Object var2);
}

